<?php
/**
 * This file is part from Ewuroweb Shop
 *
 * @package 
 * @author Ivan I. Atanasov <i.atanasov@viscomp.bg>
 */

require_once dirname(__FILE__).'/VisSeleniumTestCase.php';

class VisSeleniumXml {
    
    /**
     * TestCases instances created from this xml
     * 
     * @var array
     * @access private
     */
    private $_testCases = array();
    
    /**
     * Absolute path of xml file
     * 
     * @var string
     * @access private
     */
    private $_xml = '';
    
    /**
     * Default Constructor
     * 
     * @param string $file Absolute path of xml file
     * @return VisSeleniumXml
     */
    function __construct($file) {
        $this->_xml = $file;
        $this->_parseXml();
    }
    //=============================================================================================
    
    function testCases() {
        return $this->_testCases;
    }
    //=============================================================================================
    
    private function _parseXml() {
        $doc = new DOMDocument();
        $doc->load($this->_xml);
        
        $testCases = $doc->getElementsByTagName("TestCase");
        foreach( $testCases as $tc ) {
            $testCase = new VisSeleniumTestCase($tc->getAttribute('name'));
            
            $commands = $tc->getElementsByTagName( "command" );
            foreach($commands as $c) {
                $aCommand['command'] = $c->getAttribute('name');
                $aCommand['target'] = $c->getAttribute('target');
                $aCommand['value'] = $c->getAttribute('value');
                
                $testCase->addCommand($aCommand);
            }
            
            $this->_testCases[] = $testCase;
        }
    }
    //=============================================================================================
    
}